var app = angular.module('app',[]).controller('signin',
		function($scope, $http){
	$scope.user={};
	var flag = false;
	
	$scope.userRegister = function (){
		if($scope.user.name == null || $scope.user.name == '') {
			$scope.msg1 = "请输入用户名";
			return;
		}else{
			flag = true;
		}
		if($scope.user.realName == null || $scope.user.realName == '') {
			$scope.msg11 = "请输入真实姓名";
			return;
		}else{
			flag = true;
		}
		if($scope.user.xh == null || $scope.user.xh == '') {
			$scope.msg2 = "请输入身份证号";
			return ;
		}else{
			// 身份证号码18位，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
			   var reg = /(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
			   if(reg.test($scope.user.xh)===false)  
			   {  
				   $scope.msg2 = "身份证输入不合法";  
			       return ;  
			   } 
			flag = true;
		}
		if($scope.user.phone == null || $scope.user.phone == '') {
			$scope.msg3 = "请输入手机号";
			return ;
		}else{
			var reg = /^1\d{10}$/;
			if(reg.test($scope.user.phone)===false){
				$scope.msg3 = "手机号码有误";
				return;
			}
			flag = true;
		}
		if($scope.user.email == null || $scope.user.email == '') {
			$scope.msg33 = "请输入邮箱";
			return ;
		}else{
			var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(reg.test($scope.user.email)===false){
				$scope.msg33 = "邮箱格式有误";
				return;
			}
			flag = true;
		}
		if($scope.user.srPwd == null || $scope.user.srPwd == '') {
			$scope.msg4 = "请输入密码";
			return ;
		}else{
			flag = true;
		}
		if($scope.user.qrPwd == null || $scope.user.qrPwd == '') {
			$scope.msg5 = "请输入确认密码";
			return ;
		}else{
			flag = true;
		}
		if($scope.rentCar == null || $scope.rentCar == '') {
			$scope.msg6 = "请接受租车协议";
			return ;
		}else{
			flag = true;
		}
		if($scope.user.qrPwd == $scope.user.srPwd){
		if(flag){
			$http.post("./userRegister",$scope.user).success(function(data){
				if(data.status == "ok"){
					
					alert("注册成功！跳转到登录界面");
					window.open("./userlogin");
				}else{
					$scope.msg1 = "用户名已经存在，请重新输入!";
					return;
				}
			})
			
		}
		}else{
			$scope.msg5 = "确认密码和输入密码不同，请重新输入！";
			return;
		}
	}
	
	$scope.onmouse1 = function(){
		$scope.msg1 = "";
	}
	$scope.onmouse11 = function(){
		$scope.msg11 = "";
	}
	$scope.onmouse2 = function(){
		$scope.msg2 = "";
	}
	$scope.onmouse3 = function(){
		$scope.msg3 = "";
	}
	$scope.onmouse33 = function(){
		$scope.msg33 = "";
	}
	$scope.onmouse4 = function(){
		$scope.msg4 = "";
	}
	$scope.onmouse5 = function(){
		$scope.msg5 = "";
	}
	$scope.onmouse6 = function(){
		$scope.msg6 = "";
	}
})